/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etp.coofy.Commands;

import etp.USB.USBService;
import etp.coofy.Coofy;

/**
 *
 * @author mikulski
 */
public class USB_Heater extends etp.USB.USBCommand implements etp.USB.OutputCommand, etp.USB.InputCommand{
    public static int COMMAND = 0x54;
    private byte[] out;
    private Coofy surface;
    
    public USB_Heater(Coofy surface) {
        this.surface = surface;
    }
    
    @Override
    public void sendCommand(USBService usbs) {
        this.sendCommand(usbs, false);                
    }

    @Override
    public void sendCommand(USBService usbs, byte[] bytes) {
        this.sendCommand(usbs);
    }
    /**
     * Schaltet den Thermoblock ein oder aus
     * @param usbs USB Service
     * @param on true -> Thermoblock ein; false -> Thermoblock aus
     */
    public void sendCommand(USBService usbs, boolean on) {
        this.out = this.getSendBuffer();
        out[0] = (byte) COMMAND;
        if(on) {
            out[1] = 0x0F;
        } else {
            out[1] = 0x00;
        }
        usbs.sendCommand(out);
        usbs.registerCommand((byte) COMMAND, this);
    }

    @Override
    public void receiveUSB(byte[] in) {
        if(in[1] == 0x01) {
            this.surface.setHeaterStatus(false);
        } else {
            this.surface.setHeaterStatus(true);
        }
    }
    
}
